class Page8 extends egret.Sprite{
	private building:egret.Bitmap;
	private blink:egret.Bitmap;
	private arr_pic;

	private bg1:egret.Bitmap;
	private bg2:egret.Bitmap;
	private bg3:egret.Bitmap;

	private arr_bd;

	public constructor() {
		super();
		this.initial();
	}
	public initial(){
		this.bg1=new egret.Bitmap(RES.getRes("bg8_png"));
		this.addChild(this.bg1);
		this.bg2=new egret.Bitmap(RES.getRes("bg888_png"));
		
		
		this.bg3=new egret.Bitmap(RES.getRes("bg88_png"));
		this.addChild(this.bg3);

		this.bg2.x=180;this.bg2.y=126;
		this.bg3.x=0;this.bg3.y=394;

		this.arr_bd=new Array();
		for(var k=1;k<=6;k++){
			var pic=new egret.Bitmap(RES.getRes("bd"+k+"_png"));
			this.addChild(pic);
			this.arr_bd.push(pic);
			switch(k){
				case 1:pic.x=318;pic.y=126;break;
				case 2:pic.x=422;pic.y=259;break;
				case 3:pic.x=422;pic.y=313;break;
				case 4:pic.x=424;pic.y=377;break;
				case 5:pic.x=180;pic.y=279;break;
				case 6:pic.x=186;pic.y=380;break;
			}
		}
		this.addChild(this.bg2);


		this.arr_pic=new Array();
		for(var z=1;z<=9;z++){
			var pic=new egret.Bitmap(RES.getRes("page8pic"+z+"_png"));
			this.addChild(pic);
			switch(z){
				case 1:pic.x=224;pic.y=470;break;
				case 2:pic.x=292;pic.y=601;break;
				case 3:pic.x=153;pic.y=657;break;
				case 4:pic.x=224;pic.y=713;break;
				case 5:pic.x=190;pic.y=929;break;
				case 6:pic.x=242;pic.y=978;break;
				case 7:pic.x=305;pic.y=765;break;
				case 8:pic.x=688;pic.y=805;break;
				case 9:pic.x=578;pic.y=63;break;
			}
			if(z==7){
				pic.anchorOffsetX=pic.width/2;pic.anchorOffsetY=pic.height/2;
				pic.x=305+pic.width/2;pic.y=765+pic.height/2;
			}
			this.arr_pic.push(pic);
		}
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.TB,this);

	}
	private TB(e:TouchEvent){
		this.touchEnabled=false;
		GoEvent.msg.dispatchEvent(new GoEvent("ChangePage","8"));
	}
	public End(){
		egret.Tween.get(this).to({alpha:0},600,egret.Ease.cubicOut);
	}

	public Show(){
		// this.touchEnabled=true;


		var This=this;
		this.alpha=0;
		egret.Tween.get(this).to({alpha:1},700,egret.Ease.cubicOut);
		
		// this.bg2.x=70;


		this.bg2.alpha=0;
		this.bg3.alpha=0;

		egret.Tween.get(this.bg2).wait(1750).to({alpha:1},1000);
		egret.Tween.get(this.bg3).wait(1700).to({alpha:1},900,egret.Ease.cubicOut);


		for(var z=0;z<this.arr_bd.length;z++){
			var xx;
			var yy;
			this.arr_bd[z].alpha=0;
			switch(z){
				case 0:this.arr_bd[z].x=318;this.arr_bd[z].y=126-150;break;
				case 1:this.arr_bd[z].x=422+120;this.arr_bd[z].y=259-140;break;
				case 2:this.arr_bd[z].x=422+150;this.arr_bd[z].y=313-60;break;
				case 3:this.arr_bd[z].x=424+80;this.arr_bd[z].y=377+130;break;
				case 4:this.arr_bd[z].x=180-140;this.arr_bd[z].y=279-150;break;
				case 5:this.arr_bd[z].x=186-140;this.arr_bd[z].y=380+140;break;
			}
			// this.arr_bd[z].rotation=360*Math.random();
			this.arr_bd[z].scaleX=4.5;
			this.arr_bd[z].scaleY=4.5;
			switch(z){
				case 0:xx=318;yy=126;break;
				case 1:xx=422;yy=259;break;
				case 2:xx=422;yy=313;break;
				case 3:xx=424;yy=377;break;
				case 4:xx=180;yy=279;break;
				case 5:xx=186;yy=380;break;
			}
			egret.Tween.get(this.arr_bd[z]).wait(300*z).to({alpha:1,x:xx,y:yy,rotation:0,scaleX:1,scaleY:1},700,egret.Ease.cubicOut)
		}
	

		for(var z=0;z<this.arr_pic.length;z++){
			this.arr_pic[z].alpha=0;
			if(z==6){
				this.arr_pic[z].scaleX=0.2;this.arr_pic[z].scaleY=0.2;
				egret.Tween.get(this.arr_pic[z]).wait(1700+z*400-z*20).to({alpha:1,scaleX:1,scaleY:1},700,egret.Ease.backOut);
			}
			else if(z==8){
				this.arr_pic[z].x+=50;
				egret.Tween.get(this.arr_pic[z]).wait(1700+z*400-z*20).to({alpha:1,x:578},800,egret.Ease.cubicOut);
			
			}
			else {
			this.arr_pic[z].y+=50;
			egret.Tween.get(this.arr_pic[z]).wait(1700+z*400-z*20).to({alpha:1,y:this.arr_pic[z].y-50},800,egret.Ease.cubicOut);
			}
		}
	}
}